package cn.itcast.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import cn.itcast.dao.TestsDao;
import cn.itcast.mapper.TestsMapper;
import cn.itcast.util.MybatisUtil;
import cn.itcast.vo.Tests;
import cn.itcast.vo.extend.TestsExtend;
import cn.itcast.vo.query.TestsQuery;

public class TestsDaoImpl implements TestsDao{
	private SqlSessionFactory sqlSessionFactory;

	public TestsDaoImpl() {
		  sqlSessionFactory=MybatisUtil.getSqlSessionFactory();
		  System.out.println("SqlSessionFactory工厂:"+sqlSessionFactory.toString());
	}
	@Override
	public List<TestsExtend> getTestsByChapterId(int id) {
		List<TestsExtend> list = null;
		SqlSession sqlSession = sqlSessionFactory.openSession();
		TestsMapper testsMapper=sqlSession.getMapper(TestsMapper.class);
		list=testsMapper.getTestsByChapterId(id);
		System.out.println(list.size()+"###########");
		System.out.println(list.toString());
		sqlSession.close();
		return list;
	}
	
	@Override
	public List<TestsExtend> getTestsByTestsType(TestsQuery tq) {
		List<TestsExtend> list = null;
		SqlSession sqlSession = sqlSessionFactory.openSession();
		TestsMapper testsMapper=sqlSession.getMapper(TestsMapper.class);
		list=testsMapper.getTestsByTestsType(tq);
		sqlSession.close();
		return list;
	}
	@Override
	public int getChapterSum(int textBookId) {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		TestsMapper testsMapper=sqlSession.getMapper(TestsMapper.class);
		int sum=testsMapper.getChapterSum(1);
		System.out.println("章节数量:"+sum);
		return sum;
	}

	

}
